using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml;
public class SqlUtil
{
	private SqlUtil()
	{
	}
	protected void method_0(IDataParameter[] idataParameter_0, DataRow dataRow_0)
	{
		if (idataParameter_0 != null && dataRow_0 != null)
		{
			DataColumnCollection columns = dataRow_0.Table.Columns;
			int num = 0;
			for (int i = 0; i < idataParameter_0.Length; i++)
			{
				IDataParameter dataParameter = idataParameter_0[i];
				if (dataParameter.ParameterName == null || dataParameter.ParameterName.Length <= 1)
				{
					throw new InvalidOperationException(string.Format("Please provide a valid parameter name on the parameter #{0}, the ParameterName property has the following value: '{1}'.", num, dataParameter.ParameterName));
				}
				if (columns.Contains(dataParameter.ParameterName))
				{
					dataParameter.Value = dataRow_0[dataParameter.ParameterName];
				}
				else
				{
					if (columns.Contains(dataParameter.ParameterName.Substring(1)))
					{
						dataParameter.Value = dataRow_0[dataParameter.ParameterName.Substring(1)];
					}
				}
				num++;
			}
		}
	}
	protected void method_1(IDataParameter[] idataParameter_0, params object[] object_0)
	{
		if (idataParameter_0 != null && object_0 != null)
		{
			if (idataParameter_0.Length != object_0.Length)
			{
				throw new ArgumentException("Parameter count does not match Parameter Value count.");
			}
			int i = 0;
			int num = idataParameter_0.Length;
			int num2 = 0;
			while (i < num)
			{
				if (idataParameter_0[i].Direction != ParameterDirection.ReturnValue)
				{
					if (object_0[num2] is IDataParameter)
					{
						IDataParameter dataParameter = (IDataParameter)object_0[num2];
						if (dataParameter.Direction == ParameterDirection.ReturnValue)
						{
							dataParameter = (IDataParameter)object_0[++num2];
						}
						if (dataParameter.Value == null)
						{
							idataParameter_0[i].Value = DBNull.Value;
						}
						else
						{
							idataParameter_0[i].Value = dataParameter.Value;
						}
					}
					else
					{
						if (object_0[num2] == null)
						{
							idataParameter_0[i].Value = DBNull.Value;
						}
						else
						{
							idataParameter_0[i].Value = object_0[num2];
						}
					}
					num2++;
				}
				i++;
			}
		}
	}
	public static SQLiteCommand smethod_0(SQLiteConnection sqliteConnection_0, string string_0, params SQLiteParameter[] sqliteParameter_0)
	{
		SQLiteCommand sQLiteCommand = new SQLiteCommand(string_0, sqliteConnection_0);
		if (sqliteParameter_0.Length > 0)
		{
			for (int i = 0; i < sqliteParameter_0.Length; i++)
			{
				SQLiteParameter parameter = sqliteParameter_0[i];
				sQLiteCommand.Parameters.Add(parameter);
			}
		}
		return sQLiteCommand;
	}
	public static SQLiteCommand smethod_1(string string_0, string string_1, params SQLiteParameter[] sqliteParameter_0)
	{
		SQLiteConnection connection = new SQLiteConnection(string_0);
		SQLiteCommand sQLiteCommand = new SQLiteCommand(string_1, connection);
		if (sqliteParameter_0.Length > 0)
		{
			for (int i = 0; i < sqliteParameter_0.Length; i++)
			{
				SQLiteParameter parameter = sqliteParameter_0[i];
				sQLiteCommand.Parameters.Add(parameter);
			}
		}
		return sQLiteCommand;
	}
	public static int smethod_10(string string_0, string string_1, params object[] object_0)
	{
		SQLiteConnection sQLiteConnection = new SQLiteConnection(string_0);
		SQLiteCommand sQLiteCommand = sQLiteConnection.CreateCommand();
		sQLiteCommand.CommandText = string_1;
		SqlUtil.smethod_16(sQLiteCommand, string_1, object_0);
		if (sQLiteConnection.State == ConnectionState.Closed)
		{
			sQLiteConnection.Open();
		}
		int result = sQLiteCommand.ExecuteNonQuery();
		sQLiteCommand.Dispose();
		sQLiteConnection.Close();
		return result;
	}
	public static int smethod_11(SQLiteConnection sqliteConnection_0, string string_0, params object[] object_0)
	{
		SQLiteCommand sQLiteCommand = sqliteConnection_0.CreateCommand();
		sQLiteCommand.CommandText = string_0;
		SqlUtil.smethod_16(sQLiteCommand, string_0, object_0);
		if (sqliteConnection_0.State == ConnectionState.Closed)
		{
			sqliteConnection_0.Open();
		}
		int result = sQLiteCommand.ExecuteNonQuery();
		sQLiteCommand.Dispose();
		sqliteConnection_0.Close();
		return result;
	}
	public static int smethod_12(SQLiteTransaction sqliteTransaction_0, string string_0, params object[] object_0)
	{
		if (sqliteTransaction_0 == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (sqliteTransaction_0 != null && sqliteTransaction_0.Connection == null)
		{
			throw new ArgumentException("The transaction was rolled back or committed,                                                        please provide an open transaction.", "transaction");
		}
		IDbCommand dbCommand = sqliteTransaction_0.Connection.CreateCommand();
		dbCommand.CommandText = string_0;
		SqlUtil.smethod_16((SQLiteCommand)dbCommand, dbCommand.CommandText, object_0);
		if (sqliteTransaction_0.Connection.State == ConnectionState.Closed)
		{
			sqliteTransaction_0.Connection.Open();
		}
		int result = dbCommand.ExecuteNonQuery();
		dbCommand.Dispose();
		return result;
	}
	public static int smethod_13(IDbCommand idbCommand_0)
	{
		if (idbCommand_0.Connection.State == ConnectionState.Closed)
		{
			idbCommand_0.Connection.Open();
		}
		int result = idbCommand_0.ExecuteNonQuery();
		idbCommand_0.Connection.Close();
		idbCommand_0.Dispose();
		return result;
	}
	public static object smethod_14(string string_0, string string_1, params object[] object_0)
	{
		SQLiteConnection sQLiteConnection = new SQLiteConnection(string_0);
		SQLiteCommand sQLiteCommand = sQLiteConnection.CreateCommand();
		sQLiteCommand.CommandText = string_1;
		SqlUtil.smethod_16(sQLiteCommand, string_1, object_0);
		if (sQLiteConnection.State == ConnectionState.Closed)
		{
			sQLiteConnection.Open();
		}
		object result = sQLiteCommand.ExecuteScalar();
		sQLiteCommand.Dispose();
		sQLiteConnection.Close();
		return result;
	}
	public static XmlReader smethod_15(IDbCommand idbCommand_0)
	{
		if (idbCommand_0.Connection.State != ConnectionState.Open)
		{
			idbCommand_0.Connection.Open();
		}
		SQLiteDataAdapter sQLiteDataAdapter = new SQLiteDataAdapter((SQLiteCommand)idbCommand_0);
		DataSet dataSet = new DataSet();
		sQLiteDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
		sQLiteDataAdapter.Fill(dataSet);
		StringReader input = new StringReader(dataSet.GetXml());
		idbCommand_0.Connection.Close();
		return new XmlTextReader(input);
	}
	private static SQLiteParameterCollection smethod_16(SQLiteCommand sqliteCommand_0, string string_0, params object[] object_0)
	{
		if (object_0 == null || object_0.Length == 0)
		{
			return null;
		}
		SQLiteParameterCollection parameters = sqliteCommand_0.Parameters;
		string input = string_0.Substring(string_0.IndexOf("@")).Replace(",", " ,");
		string pattern = "(@)\\S*(.*?)\\b";
		MatchCollection matchCollection = new Regex(pattern, RegexOptions.IgnoreCase).Matches(input);
		string[] array = new string[matchCollection.Count];
		int num = 0;
		foreach (Match match in matchCollection)
		{
			array[num] = match.Value;
			num++;
		}
		int num2 = 0;
		int i = 0;
		while (i < object_0.Length)
		{
			object obj = object_0[i];
			Type type = obj.GetType();
			SQLiteParameter sQLiteParameter = new SQLiteParameter();
			string text = type.ToString();
			if (text != null)
			{
				if (CommonBean.dictionary == null)
				{
					CommonBean.dictionary = new Dictionary<string, int>(15)
					{

						{
							"DBNull",
							0
						},

						{
							"Char",
							1
						},

						{
							"SByte",
							2
						},

						{
							"UInt16",
							3
						},

						{
							"UInt32",
							4
						},

						{
							"UInt64",
							5
						},

						{
							"System.String",
							6
						},

						{
							"System.Byte[]",
							7
						},

						{
							"System.Int32",
							8
						},

						{
							"System.Boolean",
							9
						},

						{
							"System.DateTime",
							10
						},

						{
							"System.Double",
							11
						},

						{
							"System.Decimal",
							12
						},

						{
							"System.Guid",
							13
						},

						{
							"System.Object",
							14
						}
					};
				}
				int num3;
				if (CommonBean.dictionary.TryGetValue(text, out num3))
				{
					switch (num3)
					{
					case 0:
					case 1:
					case 2:
					case 3:
					case 4:
					case 5:
						throw new SystemException("Invalid data type");
					case 6:
						sQLiteParameter.DbType = DbType.String;
						sQLiteParameter.ParameterName = array[num2];
						sQLiteParameter.Value = (string)object_0[num2];
						parameters.Add(sQLiteParameter);
						break;
					case 7:
						sQLiteParameter.DbType = DbType.Binary;
						sQLiteParameter.ParameterName = array[num2];
						sQLiteParameter.Value = (byte[])object_0[num2];
						parameters.Add(sQLiteParameter);
						break;
					case 8:
						sQLiteParameter.DbType = DbType.Int32;
						sQLiteParameter.ParameterName = array[num2];
						sQLiteParameter.Value = (int)object_0[num2];
						parameters.Add(sQLiteParameter);
						break;
					case 9:
						sQLiteParameter.DbType = DbType.Boolean;
						sQLiteParameter.ParameterName = array[num2];
						sQLiteParameter.Value = (bool)object_0[num2];
						parameters.Add(sQLiteParameter);
						break;
					case 10:
						sQLiteParameter.DbType = DbType.DateTime;
						sQLiteParameter.ParameterName = array[num2];
						sQLiteParameter.Value = Convert.ToDateTime(object_0[num2]);
						parameters.Add(sQLiteParameter);
						break;
					case 11:
						sQLiteParameter.DbType = DbType.Double;
						sQLiteParameter.ParameterName = array[num2];
						sQLiteParameter.Value = Convert.ToDouble(object_0[num2]);
						parameters.Add(sQLiteParameter);
						break;
					case 12:
						sQLiteParameter.DbType = DbType.Decimal;
						sQLiteParameter.ParameterName = array[num2];
						sQLiteParameter.Value = Convert.ToDecimal(object_0[num2]);
						break;
					case 13:
						sQLiteParameter.DbType = DbType.Guid;
						sQLiteParameter.ParameterName = array[num2];
						sQLiteParameter.Value = (Guid)object_0[num2];
						break;
					case 14:
						sQLiteParameter.DbType = DbType.Object;
						sQLiteParameter.ParameterName = array[num2];
						sQLiteParameter.Value = object_0[num2];
						parameters.Add(sQLiteParameter);
						break;
					default:
						goto IL_3E9;
					}
					num2++;
					i++;
					continue;
				}
			}
			IL_3E9:
			throw new SystemException("Value is of unknown data type");
		}
		return parameters;
	}
	public static int smethod_17(IDbCommand idbCommand_0, DataRow dataRow_0)
	{
		if (dataRow_0 != null && dataRow_0.ItemArray.Length > 0)
		{
			SqlUtil.smethod_18(idbCommand_0.Parameters, dataRow_0);
			return SqlUtil.smethod_13(idbCommand_0);
		}
		return SqlUtil.smethod_13(idbCommand_0);
	}
	protected internal static void smethod_18(IDataParameterCollection idataParameterCollection_0, DataRow dataRow_0)
	{
		if (idataParameterCollection_0 != null && dataRow_0 != null)
		{
			DataColumnCollection columns = dataRow_0.Table.Columns;
			int num = 0;
			foreach (IDataParameter dataParameter in idataParameterCollection_0)
			{
				if (dataParameter.ParameterName == null || dataParameter.ParameterName.Length <= 1)
				{
					throw new InvalidOperationException(string.Format("Please provide a valid parameter name on the parameter #{0},                            the ParameterName property has the following value: '{1}'.", num, dataParameter.ParameterName));
				}
				if (columns.Contains(dataParameter.ParameterName))
				{
					dataParameter.Value = dataRow_0[dataParameter.ParameterName];
				}
				else
				{
					if (columns.Contains(dataParameter.ParameterName.Substring(1)))
					{
						dataParameter.Value = dataRow_0[dataParameter.ParameterName.Substring(1)];
					}
				}
				num++;
			}
		}
	}
	public static SQLiteParameter smethod_2(string string_0, DbType dbType_0, object object_0)
	{
		return new SQLiteParameter
		{
			DbType = dbType_0,
			ParameterName = string_0,
			Value = object_0
		};
	}
	public static DataSet smethod_3(string string_0, string string_1, object[] object_0)
	{
		SQLiteConnection sQLiteConnection = new SQLiteConnection(string_0);
		SQLiteCommand sQLiteCommand = sQLiteConnection.CreateCommand();
		sQLiteCommand.CommandText = string_1;
		if (object_0 != null)
		{
			SqlUtil.smethod_16(sQLiteCommand, string_1, object_0);
		}
		DataSet dataSet = new DataSet();
		if (sQLiteConnection.State == ConnectionState.Closed)
		{
			sQLiteConnection.Open();
		}
		SQLiteDataAdapter sQLiteDataAdapter = new SQLiteDataAdapter(sQLiteCommand);
		sQLiteDataAdapter.Fill(dataSet);
		sQLiteDataAdapter.Dispose();
		sQLiteCommand.Dispose();
		sQLiteConnection.Close();
		return dataSet;
	}
	public static DataSet smethod_4(SQLiteConnection sqliteConnection_0, string string_0, object[] object_0)
	{
		SQLiteCommand sQLiteCommand = sqliteConnection_0.CreateCommand();
		sQLiteCommand.CommandText = string_0;
		if (object_0 != null)
		{
			SqlUtil.smethod_16(sQLiteCommand, string_0, object_0);
		}
		DataSet dataSet = new DataSet();
		if (sqliteConnection_0.State == ConnectionState.Closed)
		{
			sqliteConnection_0.Open();
		}
		SQLiteDataAdapter sQLiteDataAdapter = new SQLiteDataAdapter(sQLiteCommand);
		sQLiteDataAdapter.Fill(dataSet);
		sQLiteDataAdapter.Dispose();
		sQLiteCommand.Dispose();
		sqliteConnection_0.Close();
		return dataSet;
	}
	public static DataSet smethod_5(SQLiteCommand sqliteCommand_0)
	{
		if (sqliteCommand_0.Connection.State == ConnectionState.Closed)
		{
			sqliteCommand_0.Connection.Open();
		}
		DataSet dataSet = new DataSet();
		SQLiteDataAdapter sQLiteDataAdapter = new SQLiteDataAdapter(sqliteCommand_0);
		sQLiteDataAdapter.Fill(dataSet);
		sQLiteDataAdapter.Dispose();
		sqliteCommand_0.Connection.Close();
		sqliteCommand_0.Dispose();
		return dataSet;
	}
	public static DataSet smethod_6(SQLiteTransaction sqliteTransaction_0, string string_0, params SQLiteParameter[] sqliteParameter_0)
	{
		if (sqliteTransaction_0 == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (sqliteTransaction_0 != null && sqliteTransaction_0.Connection == null)
		{
			throw new ArgumentException("The transaction was rolled back or committed, please provide an open transaction.", "transaction");
		}
		IDbCommand dbCommand = sqliteTransaction_0.Connection.CreateCommand();
		dbCommand.CommandText = string_0;
		for (int i = 0; i < sqliteParameter_0.Length; i++)
		{
			SQLiteParameter value = sqliteParameter_0[i];
			dbCommand.Parameters.Add(value);
		}
		if (sqliteTransaction_0.Connection.State == ConnectionState.Closed)
		{
			sqliteTransaction_0.Connection.Open();
		}
		return SqlUtil.smethod_5((SQLiteCommand)dbCommand);
	}
	public static DataSet smethod_7(SQLiteTransaction sqliteTransaction_0, string string_0, object[] object_0)
	{
		if (sqliteTransaction_0 == null)
		{
			throw new ArgumentNullException("transaction");
		}
		if (sqliteTransaction_0 != null && sqliteTransaction_0.Connection == null)
		{
			throw new ArgumentException("The transaction was rolled back or committed,                                                          please provide an open transaction.", "transaction");
		}
		IDbCommand dbCommand = sqliteTransaction_0.Connection.CreateCommand();
		dbCommand.CommandText = string_0;
		SqlUtil.smethod_16((SQLiteCommand)dbCommand, dbCommand.CommandText, object_0);
		if (sqliteTransaction_0.Connection.State == ConnectionState.Closed)
		{
			sqliteTransaction_0.Connection.Open();
		}
		return SqlUtil.smethod_5((SQLiteCommand)dbCommand);
	}
	public static void smethod_8(SQLiteCommand sqliteCommand_0, SQLiteCommand sqliteCommand_1, SQLiteCommand sqliteCommand_2, DataSet dataSet_0, string string_0)
	{
		if (sqliteCommand_0 == null)
		{
			throw new ArgumentNullException("insertCommand");
		}
		if (sqliteCommand_1 == null)
		{
			throw new ArgumentNullException("deleteCommand");
		}
		if (sqliteCommand_2 == null)
		{
			throw new ArgumentNullException("updateCommand");
		}
		if (string_0 == null || string_0.Length == 0)
		{
			throw new ArgumentNullException("tableName");
		}
		using (SQLiteDataAdapter sQLiteDataAdapter = new SQLiteDataAdapter())
		{
			sQLiteDataAdapter.UpdateCommand = sqliteCommand_2;
			sQLiteDataAdapter.InsertCommand = sqliteCommand_0;
			sQLiteDataAdapter.DeleteCommand = sqliteCommand_1;
			sQLiteDataAdapter.Update(dataSet_0, string_0);
			dataSet_0.AcceptChanges();
		}
	}
	public static IDataReader smethod_9(SQLiteCommand sqliteCommand_0, string string_0, object[] object_0)
	{
		if (sqliteCommand_0.Connection == null)
		{
			throw new ArgumentException("Command must have live connection attached.", "cmd");
		}
		sqliteCommand_0.CommandText = string_0;
		SqlUtil.smethod_16(sqliteCommand_0, string_0, object_0);
		if (sqliteCommand_0.Connection.State == ConnectionState.Closed)
		{
			sqliteCommand_0.Connection.Open();
		}
		return sqliteCommand_0.ExecuteReader(CommandBehavior.CloseConnection);
	}
}
